package com.contract.controller;

import com.contract.pojo.input.RegisterQueryInput;
import com.contract.pojo.input.RegisterRejectInput;
import com.contract.pojo.input.RegisterSaveInput;
import com.contract.pojo.output.CardBackOutput;
import com.contract.pojo.output.CardFaceOutput;
import com.contract.pojo.output.CheckFaceOutput;
import com.contract.pojo.output.JsonResult;
import com.contract.pojo.output.PageOutput;
import com.contract.pojo.output.RegisterOutput;
import com.contract.service.SysRegisterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 用户controller
 *
 * @author liw
 * @version 1.0
 * @date 2022/8/13 11:10
 */
@ApiOperation("用户")
@RestController
@RequestMapping("contract/register")
public class SysRegisterController {

    @Autowired
    private SysRegisterService sysRegisterService;

    @PostMapping("checkFace")
    @ApiOperation("校验图片")
    @PreAuthorize("hasAuthority('register_check_face')")
    public JsonResult<CheckFaceOutput> checkFace(@RequestHeader("token") String token, @RequestParam("file") @NotNull MultipartFile file) {
        return sysRegisterService.checkFace(file);
    }

    @PostMapping("cardFace")
    @ApiOperation("上传正面")
    @PreAuthorize("hasAuthority('register_card_face')")
    public JsonResult<CardFaceOutput> uploadCardFace(@RequestHeader("token") String token, @RequestParam("file") @NotNull MultipartFile file) {
        return sysRegisterService.uploadCardFace(file);
    }

    @PostMapping("cardBack")
    @ApiOperation("上传反面")
    @PreAuthorize("hasAuthority('register_card_back')")
    public JsonResult<CardBackOutput> uploadCardBack(@RequestHeader("token") String token, @RequestParam("file") @NotNull MultipartFile file) {
        return sysRegisterService.uploadCardBack(file);
    }

    @PostMapping("info")
    @ApiOperation("新增")
    @PreAuthorize("hasAuthority('register_save')")
    public JsonResult<Long> save(@RequestHeader("token") String token, @Valid @RequestBody RegisterSaveInput vo) {
        return sysRegisterService.save(vo);
    }

    @GetMapping("list")
    @ApiOperation("查询列表")
    @PreAuthorize("hasAuthority('register_list')")
    public JsonResult<PageOutput<RegisterOutput>> queryList(@RequestHeader("token") String token, RegisterQueryInput vo) {
        return sysRegisterService.queryList(vo);
    }

    @GetMapping("approved/{id}")
    @ApiOperation("审核通过")
    @PreAuthorize("hasAuthority('register_approved')")
    public JsonResult<Long> approved(@RequestHeader("token") String token, @PathVariable("id") Long id) {
        return sysRegisterService.approved(id);
    }

    @GetMapping("reject")
    @ApiOperation("审核驳回")
    @PreAuthorize("hasAuthority('register_reject')")
    public JsonResult<Long> reject(@RequestHeader("token") String token, RegisterRejectInput vo) {
        return sysRegisterService.reject(vo);
    }

    @GetMapping("info/{id}")
    @ApiOperation("查询详情")
    @PreAuthorize("hasAuthority('register_info')")
    public JsonResult<RegisterOutput> queryInfo(@RequestHeader("token") String token, @PathVariable("id") Long id) {
        return sysRegisterService.queryInfo(id);
    }

    @GetMapping("info/non")
    @ApiOperation("查询详情")
    @PreAuthorize("hasAuthority('register_info_non')")
    public JsonResult<RegisterOutput> queryInfoNon(@RequestHeader("token") String token) {
        return sysRegisterService.queryInfoNon();
    }

}
